import 'package:flutter/material.dart';
import 'package:kxy_flutter_app/components/exam_card_dot/error_dot.dart';
import 'package:kxy_flutter_app/components/exam_card_dot/right_dot.dart';
import 'package:kxy_flutter_app/components/exam_card_dot/un_answer_dot.dart';
import 'package:kxy_flutter_app/model/exam_question.dart';
import 'package:kxy_flutter_app/model/exam_result.dart';
import 'package:kxy_flutter_app/view/examination/question_review_view.dart';

class ExamResultBodyWidget extends StatelessWidget {
  final ExamResult result;
  final List<Question> quesList;
  const ExamResultBodyWidget({
    Key key,
    @required this.result,
    @required this.quesList,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    int total = result.quesRight + result.quesError + result.quesNull;
    return Container(
      height: 260,
      margin: EdgeInsets.symmetric(horizontal: 20),
      padding: EdgeInsets.symmetric(horizontal: 20, vertical: 20),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.vertical(
          bottom: Radius.circular(12),
        ),
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              countItem(result.quesRight, 1),
              countItem(result.quesError, 2),
              countItem(result.quesNull, 0),
            ],
          ),
          Padding(
            padding: EdgeInsets.symmetric(vertical: 20),
            child: Text(
              '本次答题共计$total题，加油！',
              style: TextStyle(
                fontSize: 14,
                color: Colors.black54,
              ),
            ),
          ),
          Expanded(
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceAround,
              crossAxisAlignment: CrossAxisAlignment.end,
              children: [
                FlatButton(
                  color: Colors.grey[300],
                  textColor: Colors.black54,
                  child: Text('返回上一页'),
                  onPressed: () {
                    Navigator.pop(context);
                  },
                ),
                FlatButton(
                  child: Text('查看答题卡'),
                  color: Theme.of(context).primaryColor,
                  textColor: Colors.white,
                  onPressed: () {
                    Navigator.push(
                      context,
                      MaterialPageRoute(
                        builder: (cxt) => QuestionReviewView(quesList: quesList),
                      ),
                    );
                  },
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }

  // type 0: 未答题
  // type 1: 答对题
  // type 2: 答错题
  Widget countItem(int count, int type) {
    Widget dot;
    if (type == 0) {
      dot = UnAnswerDot();
    } else if (type == 1) {
      dot = RightDot();
    } else if (type == 2) {
      dot = ErrorDot();
    } else {
      dot = Text('未知结果');
    }

    var counter = Row(
      crossAxisAlignment: CrossAxisAlignment.end,
      children: [
        Text(
          count.toString(),
          style: TextStyle(
            fontSize: 24,
            color: Colors.black87,
          ),
        ),
        Text(
          '题',
          style: TextStyle(
            fontSize: 14,
            color: Colors.black87,
          ),
        )
      ],
    );

    return Container(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          counter,
          Padding(child: dot, padding: EdgeInsets.only(top: 5)),
        ],
      ),
    );
  }
}
